package com.kayt.cyberBar.cuser.business.dao.impl;

import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kayt.cyberBar.common.PageData;
import com.kayt.cyberBar.common.dao.EntityDao;
import com.kayt.cyberBar.cuser.business.dao.ICyberBaseTaskPicDao;
import com.kayt.cyberBar.cuser.business.entity.po.BCyberBaseTaskPic;

@Repository("iCyberBaseTaskPicDao")
public class CyberBaseTaskPicDaoImpl implements ICyberBaseTaskPicDao {
	
	@Autowired
	private EntityDao entityDao;

	@Override
	public Long addPic(BCyberBaseTaskPic pic) throws SQLException {
		if (pic != null) {
			return this.entityDao.save(pic);
		}
		return 0L;
	}
	
	@Override
	public void updatePic (BCyberBaseTaskPic pic) throws SQLException {
		if (pic != null) {
			this.entityDao.update(pic);
		}
	}
	
	@Override
	public int deletePic (String pic) {
		if (pic != null) {
			this.entityDao.deleteDetached(pic);
			return 0;
		}
		return -1;
	}
	
	@Override
	public BCyberBaseTaskPic getPic (String picId) {
		BCyberBaseTaskPic bPicDetailItem = null;
		if (picId != null) {
			Long id;
			try {
				id = Long.parseLong(picId);
			} catch (Exception e) {
				return null;
			}
			bPicDetailItem = this.entityDao.findById(id, BCyberBaseTaskPic.class);
		}
		return bPicDetailItem;
	}
	
	@Override
	public BCyberBaseTaskPic getPicByCode (String reportCode) throws SQLException {
		BCyberBaseTaskPic bPicDetailItem = null;
		if (reportCode != null) {
			bPicDetailItem = this.entityDao.getObj(BCyberBaseTaskPic.class, " o.reportCode=? ", new Object[]{reportCode});
		}
		return bPicDetailItem;
	}
	
	@Override
	public PageData<BCyberBaseTaskPic> getPicList (int pageNum, int pageSize, String hql, Object[] params, LinkedHashMap<String, String> picMap) throws SQLException {
		return this.entityDao.getPagingData(BCyberBaseTaskPic.class, pageNum, pageSize, hql, params, picMap);
	}
	
	@Override
	public List getPicListByHql(int pageNum, int pageSize, String hql, Object[] params) throws SQLException {
		return this.entityDao.getPagingDataByHql(pageNum, pageSize, hql, params);
	}
}
